package cn.bocweb.spinning.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.util.Constant;
import cn.bocweb.spinning.view.adapter.ImgDetailAdapter;
import cn.bocweb.spinning.view.fragment.ImageShowFragment;

public class ImgDetailActivity extends AppCompatActivity {

    List<String> imgList;
    ImgDetailAdapter adapter;

    @Bind(R.id.viewPager_img)
    ViewPager viewPagerImg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_img_detail);
        ButterKnife.bind(this);

        initIntent();
    }

    private void initIntent() {
        Intent intent = getIntent();
        imgList = intent.getStringArrayListExtra(Constant.IMG_DETAIL_URL);

        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < imgList.size(); i++) {
            ImageShowFragment fragment = new ImageShowFragment();
            Bundle bundle = new Bundle();
            bundle.putString(Constant.IMAGE_SHOW, imgList.get(i));
            fragment.setArguments(bundle);
            fragments.add(fragment);
        }

        adapter = new ImgDetailAdapter(getSupportFragmentManager(), fragments);
        viewPagerImg.setAdapter(adapter);
    }


}
